package ystp.controller;

import jxl.Workbook;
import jxl.format.UnderlineStyle;
import jxl.write.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import ystp.model.*;
import ystp.service.YsrenyuanfenpeiService;
import ystp.service.YsxiangmuService;
import ystp.service.ZhuankeyaopinService;
import ystp.service.ZhuankeyaopinjieguoService;
import ystp.support.JsonResult;
import ystp.support.StringHandle;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.BufferedOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;

@RestController
@RequestMapping("zhuankeyaopinjieguo")
public class ZhuankeyaopinjieguoController {

    @Resource
    ZhuankeyaopinjieguoService ddService;

    @Resource
    ZhuankeyaopinService ddZhuankeyaopinService;

    @Resource
    YsxiangmuService ddYsxiangmuService;

    @Resource
    YsrenyuanfenpeiService ddYsrenyuanfenpeiService;

    public Logger log = LoggerFactory.getLogger(ZhuankeyaopinjieguoController.class);

    // 导出某个委员的签字表
    @RequestMapping("qianzibiao")
    public void qianzibiao(HttpServletRequest request, HttpServletResponse response,
                           @RequestParam("xiangmuid") String ppxiangmuid,
                           @RequestParam("xiangmuleixing") String ppxiangmuleixing,
                           @RequestParam("userid") String ppuserid) {
        try {
            ddService.daochuqianzibiao(ppxiangmuid, ppuserid, request, response);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    @RequestMapping("findHuizongbiaolist")
    public JsonResult<?> findHuizongbiaolist(@RequestParam("xiangmuid") String ppxiangmuid){
        try {
            List<Ysrenyuanfenpei> mmUserList=ddYsrenyuanfenpeiService.findUserByXiangmuId(ppxiangmuid);
            Double mm=((double)1/(double)2)*mmUserList.size();
            int mmTongguopiaoshu=(int)Math.ceil(mm);

            List<Map<String,Object>> mmList=ddZhuankeyaopinService.findZhuankeyaopinResultByXiangmuId(ppxiangmuid);
            List<Map<String,Object>> mmList1080 = ddZhuankeyaopinService.findZhuankeyaopinResult1080ByXiangmuId(ppxiangmuid);
            for (int i=0; i<mmList.size();i++) {
               // String mmDetailId = mmList.get(i).get("id").toString();
               // int mmPiaoshu = ddService.countByDetailId(mmDetailId,"1");
                String mmPiaoshu="0";
                String mmJieguotext="不通过";
                if(mmList.get(i).get("piaoshu")!=null&&!"".equals(mmList.get(i).get("piaoshu").toString())){
                    mmPiaoshu=mmList.get(i).get("piaoshu").toString();
                    String mmbeizhu=mmList.get(i).get("beizhu").toString();
                    String mmid=mmList.get(i).get("id").toString();

                    if("新引进".equals(mmbeizhu)){
                        if(Integer.valueOf(mmPiaoshu)>=mmTongguopiaoshu){
                            mmJieguotext="通过";
                        }else{
                            mmJieguotext="不通过";
                        }
                    }else {

                        List<Map<String, Object>> mmis1080List = mmList1080.stream()
                                .filter(pingui -> pingui.get("id").toString()
                                        .equals(mmid))
                                .collect(Collectors.toList());
                        if(Integer.valueOf(mmPiaoshu)>=mmTongguopiaoshu&&mmis1080List.size()>0){
                            mmJieguotext="通过";
                        }

                    }
                }else {
                    mmJieguotext="不通过";
                }
                String mmPiaoshuText = String.valueOf(mmPiaoshu) + "/" + String.valueOf(mmUserList.size());

                mmList.get(i).put("piaoshu",mmPiaoshuText);
                mmList.get(i).put("jieguo",mmJieguotext);
            }

            return JsonResult.getSuccessResult(mmList);

        }catch (Exception e) {
            e.printStackTrace();
            log.error("zhuankeyaopinjieguo/findHuizongbiaolist:error",e);
            return JsonResult.getErrorResult("zhuankeyaopinjieguo/findHuizongbiaolist:error " + e.getMessage());
        }
    }


    @RequestMapping("getZhuanKeResultCount")
    public JsonResult<?> getTiWaiResultCount(@RequestParam("xiangmuid") String ppxiangmuId,
                                             @RequestParam("userid") String ppuserId){
        try {
            Integer mmpinguishu=ddService.getZHuanKeResultCount(ppxiangmuId,ppuserId,"1");
            int mmjicaiyaoshu=ddService.getJiCaiAgreedCount(ppuserId,ppxiangmuId);
            int mmtotaljicaiyaoshu=ddZhuankeyaopinService.findAllByXiangmuIdAndJicaiyao(ppxiangmuId).size();

            Map<String, Object> mmMap = new HashMap<String, Object>();

            mmMap.put("pinguishu", mmpinguishu);
            mmMap.put("jicaiyaoshu", mmjicaiyaoshu);
            mmMap.put("shengyujicaiyaoshu", mmtotaljicaiyaoshu-mmjicaiyaoshu);
            return JsonResult.getSuccessResult(mmMap);

        }catch (Exception e) {
            e.printStackTrace();
            log.error("zhuankeyaopinjieguo/getZhuanKeResultCount:error",e);
            return JsonResult.getErrorResult("zhuankeyaopinjieguo/getZhuanKeResultCount:error " + e.getMessage());
        }

    }

    @RequestMapping("toupiao")
    public JsonResult<?> toupiao(@RequestParam("id") String ppdetailId,
                                 @RequestParam("userid") String ppuserId,
                                 @RequestParam("result") String ppresult){
        try {
            Zhuankeyaopin mmZhuankeyaopin=ddZhuankeyaopinService.findOne(ppdetailId);
            Ysxiangmu mmYsxiangmu=ddYsxiangmuService.findOne(mmZhuankeyaopin.getXiangmuid());
            if(mmYsxiangmu.getIsactived()!=1){
                return JsonResult.getErrorResult("表决失败，投票尚未启动");
            }
            Zhuankeyaopinjieguo mmZhuankeyaopinjieguo=new Zhuankeyaopinjieguo();
            if("1".equals(ppresult)) {
                String mmGuizebianhao=mmZhuankeyaopin.getGuizebianhao();

                if("是".equals(mmZhuankeyaopin.getTaotai())){
                    return JsonResult.getErrorResult("表决失败，呆滞药品，淘汰品规不可纳入");
                }
                if("是".equals(mmZhuankeyaopin.getZhusheji())&&ddService.getZhuSheJiAgreedCount(ppuserId,mmZhuankeyaopin.getXiangmuid())==8){
                    return JsonResult.getErrorResult("表决失败，中药注射剂纳入品规不得超过8");
                }

                if(ddService.getZHuanKeResultCount(mmZhuankeyaopin.getXiangmuid(),ppuserId,"1")==1080){
                    return JsonResult.getErrorResult("表决失败，勾选品规数超过1080");
                }
                if(mmGuizebianhao!=null&&!"".equals(mmGuizebianhao)) {//有规则限制

                    int mmXianzhishu=Integer.valueOf(mmZhuankeyaopin.getXianzhishu());
                    String mmXiangmuId=mmZhuankeyaopin.getXiangmuid();
                    int mmvotedagreedcount=ddService.getGuizeCount(ppuserId,mmXiangmuId,mmGuizebianhao);
                    if("1".equals(mmGuizebianhao)&&mmvotedagreedcount>=mmXianzhishu){
                        return JsonResult.getErrorResult("表决失败，品规245、246最多二选一限制数");
                    }
                    if("2".equals(mmGuizebianhao)&&mmvotedagreedcount>=mmXianzhishu){
                        return JsonResult.getErrorResult("表决失败，品规1557、1558最多二选一");
                    }
                    if("3".equals(mmGuizebianhao)&&mmvotedagreedcount>=mmXianzhishu){
                        return JsonResult.getErrorResult("表决失败3，超过限制数");
                    }
                    if("4".equals(mmGuizebianhao)&&mmvotedagreedcount>=mmXianzhishu){
                        return JsonResult.getErrorResult("表决失败，品规962、963、964最多三选二");
                    }
                    if("5".equals(mmGuizebianhao)&&mmvotedagreedcount>=mmXianzhishu){
                        return JsonResult.getErrorResult("表决失败，品规1220、1221、1222最多三选二");
                    }
                    if("6".equals(mmGuizebianhao)&&mmvotedagreedcount>=mmXianzhishu){
                        return JsonResult.getErrorResult("表决失败，品规1229、1230、1231、1232、1233、1234最多六选二");
                    }
                    if("7".equals(mmGuizebianhao)&&mmvotedagreedcount>=mmXianzhishu){
                        return JsonResult.getErrorResult("表决失败7，超过限制数");
                    }
                    if("8".equals(mmGuizebianhao)&&mmvotedagreedcount>=mmXianzhishu){
                        return JsonResult.getErrorResult("表决失败，品规1511、1513最多二选一");
                    }
                    if("9".equals(mmGuizebianhao)&&mmvotedagreedcount>=mmXianzhishu){
                        return JsonResult.getErrorResult("表决失败，品规1515、1516、1517最多三选二");
                    }
                    if("10".equals(mmGuizebianhao)&&mmvotedagreedcount>=mmXianzhishu){
                        return JsonResult.getErrorResult("表决失败10，超过限制数");
                    }
                    if("11".equals(mmGuizebianhao)&&mmvotedagreedcount>=mmXianzhishu){
                        return JsonResult.getErrorResult("表决失败，品规592、593、594、595最多四选二");
                    }
                    if("12".equals(mmGuizebianhao)&&mmvotedagreedcount>=mmXianzhishu){
                        return JsonResult.getErrorResult("表决失败，品规547、664最多二选一");
                    }
                    if("13".equals(mmGuizebianhao)&&mmvotedagreedcount>=mmXianzhishu){
                        return JsonResult.getErrorResult("表决失败，品规1585、1586、1587最多三选二");
                    }
                    if("14".equals(mmGuizebianhao)&&mmvotedagreedcount>=mmXianzhishu){
                        return JsonResult.getErrorResult("表决失败，品规602、603、604最多三选二");
                    }
                    if("15".equals(mmGuizebianhao)&&mmvotedagreedcount>=mmXianzhishu){
                        return JsonResult.getErrorResult("表决失败，品规103、1430、1431最多三选二");
                    }
                    if("16".equals(mmGuizebianhao)&&mmvotedagreedcount>=mmXianzhishu){
                        return JsonResult.getErrorResult("表决失败16，超过限制数");
                    }
                    if("17".equals(mmGuizebianhao)&&mmvotedagreedcount>=mmXianzhishu){
                        return JsonResult.getErrorResult("表决失败，品规106、971、972最多三选二");
                    }
                    if("18".equals(mmGuizebianhao)&&mmvotedagreedcount>=mmXianzhishu){
                        return JsonResult.getErrorResult("表决失败18，超过限制数");
                    }
                    if("19".equals(mmGuizebianhao)&&mmvotedagreedcount>=mmXianzhishu){
                        return JsonResult.getErrorResult("表决失败，品规1112、1113、1115最多三选二");
                    }
                    if("20".equals(mmGuizebianhao)&&mmvotedagreedcount>=mmXianzhishu){
                        return JsonResult.getErrorResult("表决失败，品规1630、1631、1632最多三选二");
                    }
                    if("21".equals(mmGuizebianhao)&&mmvotedagreedcount>=mmXianzhishu){
                        return JsonResult.getErrorResult("表决失败，品规54、56最多二选一");
                    }
                    if("22".equals(mmGuizebianhao)&&mmvotedagreedcount>=mmXianzhishu){
                        return JsonResult.getErrorResult("表决失败，品规1299、1300最多二选一");
                    }
                    if("23".equals(mmGuizebianhao)&&mmvotedagreedcount>=mmXianzhishu){
                        return JsonResult.getErrorResult("表决失败，品规1648、1649、1650最多三选二");
                    }
                    if("24".equals(mmGuizebianhao)&&mmvotedagreedcount>=mmXianzhishu){
                        return JsonResult.getErrorResult("表决失败，品规985、986、987最多三选二");
                    }
                    if("25".equals(mmGuizebianhao)&&mmvotedagreedcount>=mmXianzhishu){
                        return JsonResult.getErrorResult("表决失败，品规401、402、403最多三选二");
                    }
                    if("26".equals(mmGuizebianhao)&&mmvotedagreedcount>=mmXianzhishu){
                        return JsonResult.getErrorResult("表决失败，品规409、410、411最多三选二");
                    }
                    if("27".equals(mmGuizebianhao)&&mmvotedagreedcount>=mmXianzhishu){
                        return JsonResult.getErrorResult("表决失败27，超过限制数");
                    }
                    if("28".equals(mmGuizebianhao)&&mmvotedagreedcount>=mmXianzhishu){
                        return JsonResult.getErrorResult("表决失败，品规640、641、642最多三选二");
                    }
                    if("29".equals(mmGuizebianhao)&&mmvotedagreedcount>=mmXianzhishu){
                        return JsonResult.getErrorResult("表决失败，品规1159、1160、1161最多三选二");
                    }
                    if("30".equals(mmGuizebianhao)&&mmvotedagreedcount>=mmXianzhishu){
                        return JsonResult.getErrorResult("表决失败，品规311、312、313最多三选二");
                    }
                    if("31".equals(mmGuizebianhao)&&mmvotedagreedcount>=mmXianzhishu){
                        return JsonResult.getErrorResult("表决失败，品规1672、1673、1674最多三选二");
                    }
                    if("32".equals(mmGuizebianhao)&&mmvotedagreedcount>=mmXianzhishu){
                        return JsonResult.getErrorResult("表决失败，品规1483、1484、1485最多三选二");
                    }
                    if("33".equals(mmGuizebianhao)&&mmvotedagreedcount>=mmXianzhishu){
                        return JsonResult.getErrorResult("表决失败33，超过限制数");
                    }
                    if("34".equals(mmGuizebianhao)&&mmvotedagreedcount>=mmXianzhishu){
                        return JsonResult.getErrorResult("表决失败34，不可纳入");
                    }
                    if("35".equals(mmGuizebianhao)&&mmvotedagreedcount>=mmXianzhishu){
                        return JsonResult.getErrorResult("表决失败，品规1364、1365、1366最多三选二");
                    }
                    if("36".equals(mmGuizebianhao)&&mmvotedagreedcount>=mmXianzhishu){
                        return JsonResult.getErrorResult("表决失败，品规1382、1383、1384最多三选二");
                    }
                    if("37".equals(mmGuizebianhao)&&mmvotedagreedcount>=mmXianzhishu){
                        return JsonResult.getErrorResult("表决失败37，超过限制数");
                    }
                    if("38".equals(mmGuizebianhao)&&mmvotedagreedcount>=mmXianzhishu){
                        return JsonResult.getErrorResult("表决失败，品规340、341、1733、1734最多四选二");
                    }
                    if("39".equals(mmGuizebianhao)&&mmvotedagreedcount>=mmXianzhishu){
                        return JsonResult.getErrorResult("表决失败39，超过限制数");
                    }
                    if("40".equals(mmGuizebianhao)&&mmvotedagreedcount>=mmXianzhishu){
                        return JsonResult.getErrorResult("表决失败40，超过限制数");
                    }
                    if("41".equals(mmGuizebianhao)&&mmvotedagreedcount>=mmXianzhishu){
                        return JsonResult.getErrorResult("表决失败41，超过限制数");
                    }
                    if("42".equals(mmGuizebianhao)&&mmvotedagreedcount>=mmXianzhishu){
                        return JsonResult.getErrorResult("表决失败42，超过限制数");
                    }
                    if("43".equals(mmGuizebianhao)&&mmvotedagreedcount>=mmXianzhishu){
                        return JsonResult.getErrorResult("表决失败43，超过限制数");
                    }
                    if("44".equals(mmGuizebianhao)&&mmvotedagreedcount>=mmXianzhishu){
                        return JsonResult.getErrorResult("表决失败44，超过限制数");
                    }
                    if("45".equals(mmGuizebianhao)&&mmvotedagreedcount>=mmXianzhishu){
                        return JsonResult.getErrorResult("表决失败45，超过限制数");
                    }


                    if (ddService.checkexistByUserId(ppuserId,ppdetailId) != null) {
                        String mmId = ddService.checkexistByUserId(ppuserId,ppdetailId).getId();
                        mmZhuankeyaopinjieguo.setId(mmId);
                        mmZhuankeyaopinjieguo.setResult(ppresult);
                        mmZhuankeyaopinjieguo.setCreatetime(new Date());
                        return ddService.modify(mmZhuankeyaopinjieguo) == true ? JsonResult.getSuccessResult("表决成功")
                                : JsonResult.getErrorResult("表决失败");
                    }else {
                        mmZhuankeyaopinjieguo.setId(UUID.randomUUID().toString());
                        mmZhuankeyaopinjieguo.setDetailid(ppdetailId);
                        mmZhuankeyaopinjieguo.setUserid(ppuserId);
                        mmZhuankeyaopinjieguo.setResult(ppresult);
                        mmZhuankeyaopinjieguo.setCreatetime(new Date());
                        return ddService.add(mmZhuankeyaopinjieguo) == true ? JsonResult.getSuccessResult("表决成功")
                                : JsonResult.getErrorResult("表决失败");
                    }

                }else {

                    if (ddService.checkexistByUserId(ppuserId,ppdetailId) != null) {
                        String mmId = ddService.checkexistByUserId(ppuserId,ppdetailId).getId();
                        mmZhuankeyaopinjieguo.setId(mmId);
                        mmZhuankeyaopinjieguo.setResult(ppresult);
                        mmZhuankeyaopinjieguo.setCreatetime(new Date());
                        return ddService.modify(mmZhuankeyaopinjieguo) == true ? JsonResult.getSuccessResult("表决成功")
                                : JsonResult.getErrorResult("表决失败");
                    }else {
                        mmZhuankeyaopinjieguo.setId(UUID.randomUUID().toString());
                        mmZhuankeyaopinjieguo.setDetailid(ppdetailId);
                        mmZhuankeyaopinjieguo.setUserid(ppuserId);
                        mmZhuankeyaopinjieguo.setResult(ppresult);
                        mmZhuankeyaopinjieguo.setCreatetime(new Date());
                        return ddService.add(mmZhuankeyaopinjieguo) == true ? JsonResult.getSuccessResult("表决成功")
                                : JsonResult.getErrorResult("表决失败");
                    }

                }


            }else {
                if (ddService.checkexistByUserId(ppuserId,ppdetailId) != null) {
                    String mmId = ddService.checkexistByUserId(ppuserId,ppdetailId).getId();
                    mmZhuankeyaopinjieguo.setId(mmId);
                    mmZhuankeyaopinjieguo.setResult(ppresult);
                    mmZhuankeyaopinjieguo.setCreatetime(new Date());
                    return ddService.modify(mmZhuankeyaopinjieguo) == true ? JsonResult.getSuccessResult("表决成功")
                            : JsonResult.getErrorResult("表决失败");
                }else {
                    mmZhuankeyaopinjieguo.setId(UUID.randomUUID().toString());
                    mmZhuankeyaopinjieguo.setDetailid(ppdetailId);
                    mmZhuankeyaopinjieguo.setUserid(ppuserId);
                    mmZhuankeyaopinjieguo.setResult(ppresult);
                    mmZhuankeyaopinjieguo.setCreatetime(new Date());
                    return ddService.add(mmZhuankeyaopinjieguo) == true ? JsonResult.getSuccessResult("表决成功")
                            : JsonResult.getErrorResult("表决失败");
                }
            }


        }catch (Exception e) {
            e.printStackTrace();
            log.error("zhuankeyaopinjieguo/toupiao:error",e);
            return JsonResult.getErrorResult("zhuankeyaopinjieguo/toupiao:error " + e.getMessage());
        }
    }

    @RequestMapping("votesure")
    public JsonResult<?> votesure(@RequestParam("xiangmuid") String ppxiangmuid,
                                  @RequestParam("userid") String ppuserId){
        try {

            Ysxiangmu mmYsxiangmu=ddYsxiangmuService.findOne(ppxiangmuid);
            if(mmYsxiangmu.getIsactived()!=1){
                return JsonResult.getErrorResult("表决失败，投票尚未启动");
            }
            List<Zhuankeyaopin> mmList=ddZhuankeyaopinService.findAllByXiangmuIdAndJicaiyao(ppxiangmuid);
            for(Zhuankeyaopin mmZhuankeyaopin:mmList){
                String mmDetailId=mmZhuankeyaopin.getId();
                List<Zhuankeyaopinjieguo> mmZhuankeyaopinjieguoList=ddService.findByDetailIdAndUserId(mmDetailId,ppuserId);
                if(mmZhuankeyaopinjieguoList.size()>0){
                    String mmId=mmZhuankeyaopinjieguoList.get(0).getId();
                    Zhuankeyaopinjieguo mmZhuankeyaopinjieguo=ddService.findone(mmId);
                    mmZhuankeyaopinjieguo.setResult("1");
                    ddService.modify(mmZhuankeyaopinjieguo);
                }else {
                    Zhuankeyaopinjieguo mmZhuankeyaopinjieguo=new Zhuankeyaopinjieguo();
                    String mmId=UUID.randomUUID().toString();
                    mmZhuankeyaopinjieguo.setId(mmId);
                    mmZhuankeyaopinjieguo.setDetailid(mmDetailId);
                    mmZhuankeyaopinjieguo.setUserid(ppuserId);
                    mmZhuankeyaopinjieguo.setResult("1");
                    mmZhuankeyaopinjieguo.setCreatetime(new Date());
                    ddService.add(mmZhuankeyaopinjieguo);
                }
            }

//            mmList=ddZhuankeyaopinService.findAllByXiangmuIdAndChuangxinyao(ppxiangmuid);
//            for(Zhuankeyaopin mmZhuankeyaopin:mmList){
//                String mmDetailId=mmZhuankeyaopin.getId();
//                List<Zhuankeyaopinjieguo> mmZhuankeyaopinjieguoList=ddService.findByDetailIdAndUserId(mmDetailId,ppuserId);
//                if(mmZhuankeyaopinjieguoList.size()>0){
//                    String mmId=mmZhuankeyaopinjieguoList.get(0).getId();
//                    Zhuankeyaopinjieguo mmZhuankeyaopinjieguo=ddService.findone(mmId);
//                    mmZhuankeyaopinjieguo.setResult("1");
//                    ddService.modify(mmZhuankeyaopinjieguo);
//                }else {
//                    Zhuankeyaopinjieguo mmZhuankeyaopinjieguo=new Zhuankeyaopinjieguo();
//                    String mmId=UUID.randomUUID().toString();
//                    mmZhuankeyaopinjieguo.setId(mmId);
//                    mmZhuankeyaopinjieguo.setDetailid(mmDetailId);
//                    mmZhuankeyaopinjieguo.setUserid(ppuserId);
//                    mmZhuankeyaopinjieguo.setResult("1");
//                    mmZhuankeyaopinjieguo.setCreatetime(new Date());
//                    ddService.add(mmZhuankeyaopinjieguo);
//                }
//            }

            mmList=ddZhuankeyaopinService.findAllByXiangmuIdAndJungongyao(ppxiangmuid);
            for(Zhuankeyaopin mmZhuankeyaopin:mmList){
                String mmDetailId=mmZhuankeyaopin.getId();
                List<Zhuankeyaopinjieguo> mmZhuankeyaopinjieguoList=ddService.findByDetailIdAndUserId(mmDetailId,ppuserId);
                if(mmZhuankeyaopinjieguoList.size()>0){
                    String mmId=mmZhuankeyaopinjieguoList.get(0).getId();
                    Zhuankeyaopinjieguo mmZhuankeyaopinjieguo=ddService.findone(mmId);
                    mmZhuankeyaopinjieguo.setResult("1");
                    ddService.modify(mmZhuankeyaopinjieguo);
                }else {
                    Zhuankeyaopinjieguo mmZhuankeyaopinjieguo=new Zhuankeyaopinjieguo();
                    String mmId=UUID.randomUUID().toString();
                    mmZhuankeyaopinjieguo.setId(mmId);
                    mmZhuankeyaopinjieguo.setDetailid(mmDetailId);
                    mmZhuankeyaopinjieguo.setUserid(ppuserId);
                    mmZhuankeyaopinjieguo.setResult("1");
                    mmZhuankeyaopinjieguo.setCreatetime(new Date());
                    ddService.add(mmZhuankeyaopinjieguo);
                }
            }

            return  JsonResult.getSuccessResult("表决成功");
        }catch (Exception e) {
            e.printStackTrace();
            log.error("zhuankeyaopinjieguo/votesure:error",e);
            return JsonResult.getErrorResult("zhuankeyaopinjieguo/votesure:error " + e.getMessage());
        }
    }




    @RequestMapping("submit")
    public JsonResult<?> submit(
            @RequestParam("xiangmuid") String ppxiangmuId,
            @RequestParam("userid") String ppuserId,
            HttpServletRequest request){
        try{

            Integer mmpinguishu=ddService.getZHuanKeResultCount(ppxiangmuId,ppuserId,"1");

            int mmjicaiyaoshu=ddService.getJiCaiAgreedCount(ppuserId,ppxiangmuId);
            int mmtotaljicaiyaoshu=ddZhuankeyaopinService.findAllByXiangmuIdAndJicaiyao(ppxiangmuId).size();
            if(mmjicaiyaoshu!=mmtotaljicaiyaoshu){
                return JsonResult.getErrorResult("提交失败，集采药未勾选完毕");
            }

//            int mmchuangxinyaoshu=ddService.getChuangXinAgreedCount(ppuserId,ppxiangmuId);
//            int mmtotalchuangxinshu=ddZhuankeyaopinService.findAllByXiangmuIdAndChuangxinyao(ppxiangmuId).size();
//            if(mmchuangxinyaoshu!=mmtotalchuangxinshu){
//                return JsonResult.getErrorResult("提交失败，创新药未勾选完毕");
//            }

            int mmjungongyao=ddService.getJunGongAgreedCount(ppuserId,ppxiangmuId);
            int mmtotaljungongshu=ddZhuankeyaopinService.findAllByXiangmuIdAndJungongyao(ppxiangmuId).size();
            if(mmjungongyao!=mmtotaljungongshu){
                return JsonResult.getErrorResult("提交失败，军供站专供药品未勾选完毕");
            }

            if(mmpinguishu>1080){
                return JsonResult.getErrorResult("提交失败，勾选品规数超过1080");
            }

            List<Map<String, Object>> mmGuizeList=ddZhuankeyaopinService.findGuizebianhaoByXiangmuId(ppxiangmuId);
            for (Map<String, Object> mmGuizeMap:mmGuizeList){
                if(mmGuizeMap.get("guizebianhao")!=null&&!"".equals(mmGuizeMap.get("guizebianhao").toString())) {
                    String mmGuizebianhao = mmGuizeMap.get("guizebianhao").toString();
                    Integer mmXianzhishu = Integer.valueOf(mmGuizeMap.get("xianzhishu").toString());
                    int mmvotedagreedcount = ddService.getGuizeCount(ppuserId, ppxiangmuId, mmGuizebianhao);

                    if("1".equals(mmGuizebianhao)&&mmvotedagreedcount>mmXianzhishu){
                        return JsonResult.getErrorResult("提交失败，品规245、246最多二选一限制数");
                    }
                    if("2".equals(mmGuizebianhao)&&mmvotedagreedcount>mmXianzhishu){
                        return JsonResult.getErrorResult("提交失败，品规1557、1558最多二选一");
                    }
                    if("3".equals(mmGuizebianhao)&&mmvotedagreedcount>mmXianzhishu){
                        return JsonResult.getErrorResult("提交失败3，不满足限制要求");
                    }
                    if("4".equals(mmGuizebianhao)&&mmvotedagreedcount>mmXianzhishu){
                        return JsonResult.getErrorResult("提交失败，品规962、963、964最多三选二");
                    }
                    if("5".equals(mmGuizebianhao)&&mmvotedagreedcount>mmXianzhishu){
                        return JsonResult.getErrorResult("提交失败，品规1220、1221、1222最多三选二");
                    }
                    if("6".equals(mmGuizebianhao)&&mmvotedagreedcount>mmXianzhishu){
                        return JsonResult.getErrorResult("提交失败，品规1229、1230、1231、1232、1233、1234最多六选二");
                    }
                    if("7".equals(mmGuizebianhao)&&mmvotedagreedcount>mmXianzhishu){
                        return JsonResult.getErrorResult("提交失败7，不满足限制要求");
                    }
                    if("8".equals(mmGuizebianhao)&&mmvotedagreedcount>mmXianzhishu){
                        return JsonResult.getErrorResult("提交失败，品规1511、1513最多二选一");
                    }
                    if("9".equals(mmGuizebianhao)&&mmvotedagreedcount>mmXianzhishu){
                        return JsonResult.getErrorResult("提交失败，品规1515、1516、1517最多三选二");
                    }
                    if("10".equals(mmGuizebianhao)&&mmvotedagreedcount>mmXianzhishu){
                        return JsonResult.getErrorResult("提交失败10，不满足限制要求");
                    }
                    if("11".equals(mmGuizebianhao)&&mmvotedagreedcount>mmXianzhishu){
                        return JsonResult.getErrorResult("提交失败，品规592、593、594、595最多四选二");
                    }
                    if("12".equals(mmGuizebianhao)&&mmvotedagreedcount>mmXianzhishu){
                        return JsonResult.getErrorResult("提交失败，品规547、664最多二选一");
                    }
                    if("13".equals(mmGuizebianhao)&&mmvotedagreedcount>mmXianzhishu){
                        return JsonResult.getErrorResult("提交失败，品规1585、1586、1587最多三选二");
                    }
                    if("14".equals(mmGuizebianhao)&&mmvotedagreedcount>mmXianzhishu){
                        return JsonResult.getErrorResult("提交失败，品规602、603、604最多三选二");
                    }
                    if("15".equals(mmGuizebianhao)&&mmvotedagreedcount>mmXianzhishu){
                        return JsonResult.getErrorResult("提交失败，品规103、1430、1431最多三选二");
                    }
                    if("16".equals(mmGuizebianhao)&&mmvotedagreedcount>mmXianzhishu){
                        return JsonResult.getErrorResult("提交失败16，不满足限制要求");
                    }
                    if("17".equals(mmGuizebianhao)&&mmvotedagreedcount>mmXianzhishu){
                        return JsonResult.getErrorResult("提交失败，品规106、971、972最多三选二");
                    }
                    if("18".equals(mmGuizebianhao)&&mmvotedagreedcount>mmXianzhishu){
                        return JsonResult.getErrorResult("提交失败18，不满足限制要求");
                    }
                    if("19".equals(mmGuizebianhao)&&mmvotedagreedcount>mmXianzhishu){
                        return JsonResult.getErrorResult("提交失败，品规1112、1113、1115最多三选二");
                    }
                    if("20".equals(mmGuizebianhao)&&mmvotedagreedcount>mmXianzhishu){
                        return JsonResult.getErrorResult("提交失败，品规1630、1631、1632最多三选二");
                    }
                    if("21".equals(mmGuizebianhao)&&mmvotedagreedcount>mmXianzhishu){
                        return JsonResult.getErrorResult("提交失败，品规54、56最多二选一");
                    }
                    if("22".equals(mmGuizebianhao)&&mmvotedagreedcount>mmXianzhishu){
                        return JsonResult.getErrorResult("提交失败，品规1299、1300最多二选一");
                    }
                    if("23".equals(mmGuizebianhao)&&mmvotedagreedcount>mmXianzhishu){
                        return JsonResult.getErrorResult("提交失败，品规1648、1649、1650最多三选二");
                    }
                    if("24".equals(mmGuizebianhao)&&mmvotedagreedcount>mmXianzhishu){
                        return JsonResult.getErrorResult("提交失败，品规985、986、987最多三选二");
                    }
                    if("25".equals(mmGuizebianhao)&&mmvotedagreedcount>mmXianzhishu){
                        return JsonResult.getErrorResult("提交失败，品规401、402、403最多三选二");
                    }
                    if("26".equals(mmGuizebianhao)&&mmvotedagreedcount>mmXianzhishu){
                        return JsonResult.getErrorResult("提交失败，品规409、410、411最多三选二");
                    }
                    if("27".equals(mmGuizebianhao)&&mmvotedagreedcount>mmXianzhishu){
                        return JsonResult.getErrorResult("提交失败27，不满足限制要求");
                    }
                    if("28".equals(mmGuizebianhao)&&mmvotedagreedcount>mmXianzhishu){
                        return JsonResult.getErrorResult("提交失败，品规640、641、642最多三选二");
                    }
                    if("29".equals(mmGuizebianhao)&&mmvotedagreedcount>mmXianzhishu){
                        return JsonResult.getErrorResult("提交失败，品规1159、1160、1161最多三选二");
                    }
                    if("30".equals(mmGuizebianhao)&&mmvotedagreedcount>mmXianzhishu){
                        return JsonResult.getErrorResult("提交失败，品规311、312、313最多三选二");
                    }
                    if("31".equals(mmGuizebianhao)&&mmvotedagreedcount>mmXianzhishu){
                        return JsonResult.getErrorResult("提交失败，品规1672、1673、1674最多三选二");
                    }
                    if("32".equals(mmGuizebianhao)&&mmvotedagreedcount>mmXianzhishu){
                        return JsonResult.getErrorResult("提交失败，品规1483、1484、1485最多三选二");
                    }
                    if("33".equals(mmGuizebianhao)&&mmvotedagreedcount>mmXianzhishu){
                        return JsonResult.getErrorResult("提交失败33，不满足限制要求");
                    }
                    if("34".equals(mmGuizebianhao)&&mmvotedagreedcount>mmXianzhishu){
                        return JsonResult.getErrorResult("提交失败34，不满足限制要求");
                    }
                    if("35".equals(mmGuizebianhao)&&mmvotedagreedcount>mmXianzhishu){
                        return JsonResult.getErrorResult("提交失败，品规1364、1365、1366最多三选二");
                    }
                    if("36".equals(mmGuizebianhao)&&mmvotedagreedcount>mmXianzhishu){
                        return JsonResult.getErrorResult("提交失败36，不满足限制要求");
                    }
                    if("37".equals(mmGuizebianhao)&&mmvotedagreedcount>mmXianzhishu){
                        return JsonResult.getErrorResult("提交失败37，不满足限制要求");
                    }
                    if("38".equals(mmGuizebianhao)&&mmvotedagreedcount>mmXianzhishu){
                        return JsonResult.getErrorResult("提交失败，品规340、341、1733、1734最多四选二");
                    }
                    if("39".equals(mmGuizebianhao)&&mmvotedagreedcount>mmXianzhishu){
                        return JsonResult.getErrorResult("提交失败39，不满足限制要求");
                    }
                    if("40".equals(mmGuizebianhao)&&mmvotedagreedcount>mmXianzhishu){
                        return JsonResult.getErrorResult("提交失败40，不满足限制要求");
                    }
                    if("42".equals(mmGuizebianhao)&&mmvotedagreedcount>mmXianzhishu){
                        return JsonResult.getErrorResult("提交失败42，不满足限制要求");
                    }
                    if("43".equals(mmGuizebianhao)&&mmvotedagreedcount>mmXianzhishu){
                        return JsonResult.getErrorResult("提交失败43，不满足限制要求");
                    }
                    if("44".equals(mmGuizebianhao)&&mmvotedagreedcount>mmXianzhishu){
                        return JsonResult.getErrorResult("提交失败44，不满足限制要求");
                    }
                    if("45".equals(mmGuizebianhao)&&mmvotedagreedcount>mmXianzhishu){
                        return JsonResult.getErrorResult("提交失败45，不满足限制要求");
                    }


                }
            }


            List<Ysrenyuanfenpei>  list=ddYsrenyuanfenpeiService.findbyUserIDandXiangmuId(ppuserId,ppxiangmuId);
            Ysrenyuanfenpei mmRenyuanfenpei=ddYsrenyuanfenpeiService.findOne(list.get(0).getId());
            mmRenyuanfenpei.setIssubmit(1);
            mmRenyuanfenpei.setUpdatetime(new Date());
            HttpSession session = request.getSession();
            mmRenyuanfenpei.setUpdateby(session.getAttribute("Id").toString());
            return ddYsrenyuanfenpeiService.update(mmRenyuanfenpei)==true? JsonResult.getSuccessResult("提交成功")
                    : JsonResult.getErrorResult("提交失败");

        }catch (Exception e) {
            e.printStackTrace();
            log.error("zhuankeyaopinjieguo/submit:error",e);
            return JsonResult.getErrorResult("zhuankeyaopinjieguo/submit:error " + e.getMessage());
        }
    }

    @RequestMapping("huizongbiao")
    public void huizongbiao(HttpServletRequest request, HttpServletResponse response,
                            @RequestParam("xiangmuid") String ppxiangmuid,
                            @RequestParam("xiangmuleixing") String ppxiangmuleixing){
        List<Ysrenyuanfenpei> mmUserList=ddYsrenyuanfenpeiService.findUserByXiangmuId(ppxiangmuid);
        List<Map<String,Object>> mmList = ddZhuankeyaopinService.findZhuankeyaopinResultByXiangmuId(ppxiangmuid);

        List<Map<String,Object>> mmList1080 = ddZhuankeyaopinService.findZhuankeyaopinResult1080ByXiangmuId(ppxiangmuid);

        Double mm=((double)1/(double)2)*mmUserList.size();
        int mmTongguopiaoshu=(int)Math.ceil(mm);

        for (int i=0; i<mmList.size();i++) {
           // String mmDetailId = mmList.get(i).get("id").toString();
           // int mmPiaoshu = ddService.countByDetailId(mmDetailId,"1");
            String mmPiaoshu="0";
            String mmJieguotext="不通过";
            if(mmList.get(i).get("piaoshu")!=null&&!"".equals(mmList.get(i).get("piaoshu").toString())){
                mmPiaoshu=mmList.get(i).get("piaoshu").toString();
                String mmbeizhu=mmList.get(i).get("beizhu").toString();
                String mmid=mmList.get(i).get("id").toString();

                if("新引进".equals(mmbeizhu)){
                    if(Integer.valueOf(mmPiaoshu)>=mmTongguopiaoshu){
                        mmJieguotext="通过";
                    }else{
                        mmJieguotext="不通过";
                    }
                }else {

                    List<Map<String, Object>> mmis1080List = mmList1080.stream()
                            .filter(pingui -> pingui.get("id").toString()
                                    .equals(mmid))
                            .collect(Collectors.toList());
                    if(Integer.valueOf(mmPiaoshu)>=mmTongguopiaoshu&&mmis1080List.size()>0){
                        mmJieguotext="通过";
                    }

                }


            }else {
                mmJieguotext="不通过";
            }
            String mmPiaoshuText = String.valueOf(mmPiaoshu) + "/" + String.valueOf(mmUserList.size());

            mmList.get(i).put("piaoshu",mmPiaoshuText);
            mmList.get(i).put("jieguo",mmJieguotext);
        }
        response.reset();
        response.setContentType("application/x-download;charset=utf-8");
        OutputStream os=null;
        WritableWorkbook wbook=null;

        try {
            os = new BufferedOutputStream(response.getOutputStream());//得到输出流的语句
            //response.getOutputStream();// 取得输出流
            response.reset();// 清空输出流
            SimpleDateFormat mmDateFormat = new SimpleDateFormat("yyyyMMdd-HHmmss");
            String wenjiantitle = "专科药品目录结果汇总表" + StringHandle.tiemString(); //文件名
            String tmptitle = "东部战区总医院专科药品目录投票表"; // 标题
            response.setHeader("Content-disposition", "attachment; filename=" + new String(wenjiantitle.getBytes(), "iso8859-1") + ".xls");// 设定输出文件头
            response.setContentType("application/vnd.ms-excel");// 定义输出类型
            wbook = Workbook.createWorkbook(os); // 建立excel文件
            WritableSheet wsheet = wbook.createSheet(tmptitle, 0); // sheet名称
            // 设置excel标题
            WritableFont wfont = new WritableFont(WritableFont.ARIAL, 16, WritableFont.BOLD, false, UnderlineStyle.NO_UNDERLINE, Colour.BLACK); //设置表格样式

            WritableCellFormat wcfFC = new WritableCellFormat(wfont);
            wcfFC.setBorder(jxl.format.Border.ALL, jxl.format.BorderLineStyle.THIN); // 添加边框
            wcfFC.setVerticalAlignment(VerticalAlignment.CENTRE);   //设置居中对齐
            wcfFC.setAlignment(Alignment.CENTRE);

            WritableCellFormat wcfFC3 = new WritableCellFormat(wfont);
            wcfFC3.setVerticalAlignment(VerticalAlignment.CENTRE);   //设置居中对齐
            wcfFC3.setAlignment(Alignment.CENTRE);
            //wcfFC.setBackground(Colour.AQUA);
            Label label=new Label(0, 0, tmptitle, wcfFC3);

            WritableCellFormat cellFormat = new WritableCellFormat();
            cellFormat.setAlignment(jxl.format.Alignment.CENTRE);
            cellFormat.setVerticalAlignment(jxl.format.VerticalAlignment.CENTRE);
            cellFormat.setWrap(true);
            //cellFormat.setBackground(Colour.AQUA);
            cellFormat.setFont(wfont);
            label.setCellFormat(cellFormat);
            wsheet.addCell(label);
            wsheet.addCell(new Label(0, 0, tmptitle, wcfFC3));
            /* wsheet.addCell(new Label(7, 0, tmptitle, wcfFC));*/
            wsheet.setRowView(0,800); //第一行高度
            wsheet.setRowView(1,600); //第二行高度
            wsheet.mergeCells(0, 0, 25, 0);  //合并单元格(第一列的第一行和第十三列的第一行合并)
            wsheet.setColumnView(0,5); //宽度
            wsheet.setColumnView(1,5); //序号宽度
            wsheet.setColumnView(2,10); //药宽度
            wsheet.setColumnView(3,10); //规格宽度
            wsheet.setColumnView(4,5); //单位宽度
            wsheet.setColumnView(5,5); //医保宽度
            wsheet.setColumnView(6,5 ); //基药宽度
            wsheet.setColumnView(7,5); //1宽度
            wsheet.setColumnView(8,5); //2宽度
            wsheet.setColumnView(9,5); //3宽度
            wsheet.setColumnView(10,5); //4宽度
            wsheet.setColumnView(11,5); //5宽度
            wsheet.setColumnView(12,5); //6宽度
            wsheet.setColumnView(13,5); //1宽度
            wsheet.setColumnView(14,5); //2宽度
            wsheet.setColumnView(15,5); //3宽度
            wsheet.setColumnView(16,5); //1宽度
            wsheet.setColumnView(17,5); //2宽度
            wsheet.setColumnView(18,5); //1宽度
            wsheet.setColumnView(19,5); //2宽度
            wsheet.setColumnView(20,10); //宽度
            wsheet.setColumnView(21,10); //宽度
            wsheet.setColumnView(22,10); //宽度
            wsheet.setColumnView(23,10); //宽度

            // 开始生成主体内容
            wfont = new jxl.write.WritableFont(WritableFont.ARIAL, 10, WritableFont.BOLD, false, UnderlineStyle.NO_UNDERLINE, Colour.BLACK);
            wcfFC = new WritableCellFormat(wfont);
            wcfFC.setBorder(jxl.format.Border.ALL, jxl.format.BorderLineStyle.THIN);
            wcfFC.setVerticalAlignment(VerticalAlignment.CENTRE);   //设置居中对齐
            wcfFC.setAlignment(Alignment.CENTRE);
            wcfFC.setWrap(true);

            // 不需要边框和居中的样式
            WritableFont wfont2 = new WritableFont(WritableFont.ARIAL, 12,WritableFont.BOLD,false, UnderlineStyle.NO_UNDERLINE, Colour.BLACK); //设置表格样式
            WritableCellFormat wcfFC2 = new WritableCellFormat(wfont2);
            wcfFC2 = new WritableCellFormat(wfont2);
            wcfFC2.setWrap(true);

            wsheet.addCell(new Label(20, 1, "投票日期："+StringHandle.shorttiemString(),wcfFC2));
            wsheet.mergeCells(20, 1, 25, 1);

            // 第三行 内容
            wsheet.addCell(new Label(0, 2, "排名",wcfFC));
            wsheet.mergeCells(0, 2, 0, 3);
            wsheet.addCell(new Label(1, 2, "序号",wcfFC));
            wsheet.mergeCells(1, 2, 1, 3);
            wsheet.addCell(new Label(2, 2, "药品名称",wcfFC));
            wsheet.mergeCells(2, 2, 2, 3);
            wsheet.addCell(new Label(3, 2, "规格",wcfFC));
            wsheet.mergeCells(3, 2, 3, 3);
            wsheet.addCell(new Label(4, 2, "单位",wcfFC));
            wsheet.mergeCells(4, 2, 4, 3);
           /* wsheet.addCell(new Label(4, 2, "价格（元）",wcfFC));
            wsheet.mergeCells(4, 2, 4, 3);*/
            wsheet.addCell(new Label(5, 2, "医保类别",wcfFC));
            wsheet.mergeCells(5, 2, 5, 3);
            wsheet.addCell(new Label(6, 2, "基药",wcfFC));
            wsheet.mergeCells(6, 2, 6, 3);

            wsheet.addCell(new Label(7, 2, "建议保留条件",wcfFC));
            wsheet.mergeCells(7, 2, 12, 2);

            wsheet.addCell(new Label(13, 2, "建议淘汰条件",wcfFC));
            wsheet.mergeCells(13, 2, 15, 2);

            wsheet.addCell(new Label(16, 2, "所在目录",wcfFC));
            wsheet.mergeCells(16, 2, 17, 2);

            wsheet.addCell(new Label(18, 2, "半年无采购记录",wcfFC));
            wsheet.mergeCells(18, 2, 19, 2);

            wsheet.addCell(new Label(20, 2, "专科分组",wcfFC));
            wsheet.mergeCells(20, 2, 20, 3);

            wsheet.addCell(new Label(21, 2, "专科组预选意见",wcfFC));
            wsheet.mergeCells(21, 2, 21, 3);

            wsheet.addCell(new Label(22, 2, "预选会意见（新药、中药）",wcfFC));
            wsheet.mergeCells(22, 2, 22, 3);

            wsheet.addCell(new Label(23, 2, "备注",wcfFC));
            wsheet.mergeCells(23, 2, 23, 3);

            wsheet.addCell(new Label(24, 2, "委员表决票数(同意数/总票数)",wcfFC));
            wsheet.mergeCells(24, 2, 24, 3);

            wsheet.addCell(new Label(25, 2, "表决结果",wcfFC));
            wsheet.mergeCells(25, 2, 25, 3);
          /*  wsheet.addCell(new Label(24, 2, "排名",wcfFC));
            wsheet.mergeCells(24, 2, 24, 3);*/
            // 第四行内容

            wsheet.addCell(new Label(7, 3, "集采药",wcfFC));
            wsheet.addCell(new Label(8, 3, "通过一致性评价",wcfFC));
            wsheet.addCell(new Label(9, 3, "中药保密配方",wcfFC));
            wsheet.addCell(new Label(10, 3, "国家中药保护",wcfFC));
            wsheet.addCell(new Label(11, 3, "原国谈药",wcfFC));
            wsheet.addCell(new Label(12, 3, "创新药",wcfFC));
            wsheet.addCell(new Label(13, 3, "重点监控药",wcfFC));
            wsheet.addCell(new Label(14, 3, "中药注射剂",wcfFC));
            wsheet.addCell(new Label(15, 3, "严重不良反应",wcfFC));
          /*  wsheet.addCell(new Label(16, 3, "掉网药",wcfFC));*/
            wsheet.addCell(new Label(16, 3, "院本部",wcfFC));
            wsheet.addCell(new Label(17, 3, "秦淮",wcfFC));
            wsheet.addCell(new Label(18, 3, "院本部",wcfFC));
            wsheet.addCell(new Label(19, 3, "秦淮",wcfFC));



            // 表头结束

            wfont = new jxl.write.WritableFont(WritableFont.ARIAL, 6, WritableFont.NO_BOLD, false, UnderlineStyle.NO_UNDERLINE, Colour.BLACK);
            wcfFC = new WritableCellFormat(wfont);
            wcfFC.setBorder(jxl.format.Border.ALL, jxl.format.BorderLineStyle.THIN);
            wcfFC.setVerticalAlignment(VerticalAlignment.CENTRE);   //设置居中对齐
            wcfFC.setAlignment(Alignment.CENTRE);
            wcfFC.setWrap(true);

            int count=mmList.size();
            int mmKaishihang=4;

            for(int i=0;i<count;i++){
                Map<String,Object> mmMap = mmList.get(i);
                if (mmMap!=null) {
                    String mmxuhao = mmMap.get("xuhao") == null ? "" : mmMap.get("xuhao").toString();
                    String mmyaopinmingcheng = mmMap.get("yaopinmingcheng") == null ? "" : mmMap.get("yaopinmingcheng").toString();
                    String mmguige = mmMap.get("guige") == null ? "" : mmMap.get("guige").toString();
                    String mmdanwei = mmMap.get("danwei") == null ? "" : mmMap.get("danwei").toString();
                    String mmjiage = mmMap.get("jiage") == null ? "" : mmMap.get("jiage").toString();
                    String mmyibaoleibie = mmMap.get("yibaoleibie") == null ? "" : mmMap.get("yibaoleibie").toString();
                    String mmguojiajibenyaowu = mmMap.get("guojiajibenyaowu") == null ? "" : mmMap.get("guojiajibenyaowu").toString();
                    String mmjicaiyao = mmMap.get("jicaiyao") == null ? "" : mmMap.get("jicaiyao").toString();
                    String mmtongguopingjia = mmMap.get("tongguopingjia") == null ? "" : mmMap.get("tongguopingjia").toString();
                    String mmzhongyaobaohu = mmMap.get("zhongyaobaohu") == null ? "" : mmMap.get("zhongyaobaohu").toString();
                    String mmbaomipeifang = mmMap.get("baomipeifang") == null ? "" : mmMap.get("baomipeifang").toString();
                    String mmyuanguotanyao = mmMap.get("yuanguotanyao") == null ? "" : mmMap.get("yuanguotanyao").toString();
                    String mmchuanxinyao = mmMap.get("chuanxinyao") == null ? "" : mmMap.get("chuanxinyao").toString();
                    String mmjiankongyao = mmMap.get("jiankongyao") == null ? "" : mmMap.get("jiankongyao").toString();
                    String mmzhusheji = mmMap.get("zhusheji") == null ? "" : mmMap.get("zhusheji").toString();
                    String mmbuliangfanying = mmMap.get("buliangfanying") == null ? "" : mmMap.get("buliangfanying").toString();
                    String mmdiaowangyao = mmMap.get("diaowangyao") == null ? "" : mmMap.get("diaowangyao").toString();

                    String mmdongzongyao = mmMap.get("dongzongyao") == null ? "" : mmMap.get("dongzongyao").toString();
                    String mmdongzongjilu2 = mmMap.get("dongzongjilu2") == null ? "" : mmMap.get("dongzongjilu2").toString();
                    String mmqinhuaiyao = mmMap.get("qinhuaiyao") == null ? "" : mmMap.get("qinhuaiyao").toString();
                    String mmqinhuaijilu2 = mmMap.get("qinhuaijilu2") == null ? "" : mmMap.get("qinhuaijilu2").toString();
                    String mmbeizhu = mmMap.get("beizhu") == null ? "" : mmMap.get("beizhu").toString();
                    String mmbeizhu2 = mmMap.get("beizhu2") == null ? "" : mmMap.get("beizhu2").toString();
                    String mmzhuankefenzu = mmMap.get("zhuankefenzu") == null ? "" : mmMap.get("zhuankefenzu").toString();
                    String mmyuxuanyijian = mmMap.get("yuxuanyijian") == null ? "" : mmMap.get("yuxuanyijian").toString();


                    String mmresult = mmMap.get("result") == null ? "" : mmMap.get("result").toString();
                    String mmbiaojueren = mmMap.get("username") == null ? "" : mmMap.get("username").toString();
                    String mmpiaoshu=mmMap.get("piaoshu")==null ? "" :mmMap.get("piaoshu").toString();
                    String mmjieguo=mmMap.get("jieguo")==null ? "" :mmMap.get("jieguo").toString();

                    String mmpaiming=String.valueOf(i+1);

                    wsheet.addCell(new Label(0, mmKaishihang, mmpaiming, wcfFC));
                    wsheet.addCell(new Label(1, mmKaishihang, mmxuhao, wcfFC));
                    wsheet.addCell(new Label(2, mmKaishihang, mmyaopinmingcheng, wcfFC));
                    wsheet.addCell(new Label(3, mmKaishihang, mmguige, wcfFC));
                    wsheet.addCell(new Label(4, mmKaishihang, mmdanwei, wcfFC));
                  /*  wsheet.addCell(new Label(4, mmKaishihang, mmjiage, wcfFC));*/
                    wsheet.addCell(new Label(5, mmKaishihang, mmyibaoleibie, wcfFC));
                    wsheet.addCell(new Label(6, mmKaishihang, mmguojiajibenyaowu, wcfFC));
                    wsheet.addCell(new Label(7, mmKaishihang, mmjicaiyao, wcfFC));
                    wsheet.addCell(new Label(8, mmKaishihang, mmtongguopingjia, wcfFC));
                    wsheet.addCell(new Label(9, mmKaishihang, mmbaomipeifang, wcfFC));
                    wsheet.addCell(new Label(10, mmKaishihang, mmzhongyaobaohu, wcfFC));
                    wsheet.addCell(new Label(11, mmKaishihang, mmyuanguotanyao, wcfFC));
                    wsheet.addCell(new Label(12, mmKaishihang, mmchuanxinyao, wcfFC));
                    wsheet.addCell(new Label(13, mmKaishihang, mmjiankongyao, wcfFC));
                    wsheet.addCell(new Label(14, mmKaishihang, mmzhusheji, wcfFC));
                    wsheet.addCell(new Label(15, mmKaishihang, mmbuliangfanying, wcfFC));
                   /* wsheet.addCell(new Label(15, mmKaishihang, mmdiaowangyao, wcfFC));*/
                    wsheet.addCell(new Label(16, mmKaishihang, mmdongzongyao, wcfFC));
                    wsheet.addCell(new Label(17, mmKaishihang, mmqinhuaiyao, wcfFC));
                    wsheet.addCell(new Label(18, mmKaishihang, mmdongzongjilu2, wcfFC));
                    wsheet.addCell(new Label(19, mmKaishihang, mmqinhuaijilu2, wcfFC));
                    wsheet.addCell(new Label(20, mmKaishihang, mmzhuankefenzu, wcfFC));
                    wsheet.addCell(new Label(21, mmKaishihang, mmyuxuanyijian, wcfFC));
                    wsheet.addCell(new Label(22, mmKaishihang, mmbeizhu2, wcfFC));
                    wsheet.addCell(new Label(23, mmKaishihang, mmbeizhu, wcfFC));
                    wsheet.addCell(new Label(24, mmKaishihang, mmpiaoshu, wcfFC));
                    /*wsheet.addCell(new Label(24, mmKaishihang, mmpaiming, wcfFC));*/

                    if("通过".equals(mmjieguo)){
                        wsheet.addCell(new Label(25, mmKaishihang,mmjieguo,wcfFC));
                    }else {

                        WritableFont wfont1 = new jxl.write.WritableFont(WritableFont.ARIAL, 6, WritableFont.NO_BOLD, false, UnderlineStyle.NO_UNDERLINE, Colour.RED);
                        WritableCellFormat wcfFC1 = new WritableCellFormat(wfont1);
                        wcfFC1.setBorder(jxl.format.Border.ALL, jxl.format.BorderLineStyle.THIN);
                        wcfFC1.setVerticalAlignment(VerticalAlignment.CENTRE);   //设置居中对齐
                        wcfFC1.setAlignment(Alignment.CENTRE);
                        wcfFC1.setWrap(true);

                        wsheet.addCell(new Label(25, mmKaishihang,mmjieguo,wcfFC1));
                    }


                    mmKaishihang = mmKaishihang+1;

                }
            }
            //wsheet.setPageSetup(PageOrientation.LANDSCAPE.LANDSCAPE, PaperSize.A4,0.5d,0.5d);
            wbook.write(); // 写入文件
            wbook.close();
        } catch(Exception ex)
        {
            ex.printStackTrace();
        }finally{
            if(os!=null){
                try {
                    os.close();
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
        }

    }

}
